package com.zhan.ielts.dao.impl;

import java.util.Map;

import org.springframework.stereotype.Repository;

import com.zhan.frame.core.dao.impl.BaseDaoImpl;
import com.zhan.frame.core.exception.DaoException;
import com.zhan.frame.core.utils.BeanUtils;
import com.zhan.ielts.dao.TopicDao;
import com.zhan.ielts.domain.Param;
import com.zhan.ielts.domain.Topic;

@Repository
public class TopicDaoImpl extends BaseDaoImpl<Topic> implements TopicDao {
    @Override
    public void updateByCodePart(Topic topic) {
        sqlSessionTemplate.update(getSqlName("updateByCodePart"), topic);
    }

    @Override
    public void truncate() {
        try {
            sqlSessionTemplate.delete(getSqlName("truncate"), null);
        } catch (Exception e) {
            throw new DaoException(String.format("查询对象数量出错！语句：%s", getSqlName("updateParamVersion")), e);
        }
    }

    @Override
    public void updateParamVersion(Param param) {
        try {
            Map<String, Object> params = BeanUtils.toMap(param);
            sqlSessionTemplate.update(getSqlName("updateParamVersion"), params);
        } catch (Exception e) {
            throw new DaoException(String.format("查询对象数量出错！语句：%s", getSqlName("updateParamVersion")), e);
        }
    }

    @Override
    public String selectFrequency() {
        try {
            return sqlSessionTemplate.selectOne(getSqlName("selectFrequency"));
        } catch (Exception e) {
            throw new DaoException(String.format("查询对象总数出错！语句：%s", getSqlName("selectFrequency")), e);
        }
    }

}
